package com.rocksea.app.activity;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.rocksea.app.R;
import com.rocksea.app.entry.InspectionForm;
import com.rocksea.app.utils.UiUtils;
import com.rocksea.app.weight.DividerListItemDecoration;

import java.util.ArrayList;

import butterknife.InjectView;

/**
 * @author Administrator
 * @date 2017/11/13
 */

public class SInspecFromActivity extends BaseAppCompatActivity
{
    @InjectView(R.id.SInpecFrom_ListView)
    public RecyclerView mRecyclerView;
    private InspectionForm.InspectionFormListBean mFormListBean;
    @Override
    protected void setContentView()
    {
        setContentView(R.layout.activity_sinspecfrom_layout);
    }

    @Override
    protected void initView()
    {
        Bundle mBundle = getIntent().getBundleExtra(UiUtils.BUNDLE_KEY);
        String pileNum = mBundle.getString("PileNum");
        ActionBar actionBar = getSupportActionBar();
        if (actionBar!=null)
            getSupportActionBar().setTitle(pileNum);
        mFormListBean = mBundle.getParcelable(UiUtils.BUNDLE_KEY);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(layoutManager);
    }

    @Override
    protected void initBar(String title)
    {
        super.initBar(title);
    }

    @Override
    protected void requrstAgin()
    {
    }
    @Override
    protected void initData()
    {
        loadCompleted();
        ArrayList<String> mInfos = init(mFormListBean);
        mRecyclerView.setAdapter(new AdapterDemo(mInfos,this));
        mRecyclerView.addItemDecoration(new DividerListItemDecoration(this,DividerListItemDecoration.VERTICAL_LIST));
    }
    private static class AdapterDemo extends RecyclerView.Adapter<AdapterDemo.ViewHolder> {

        private ArrayList<String> datas;
        private Context mContext;
        private AdapterDemo(ArrayList<String> datas,Context mContext) {
            this.datas = datas;
            this.mContext = mContext;
        }
        @Override
        public AdapterDemo.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View item = LayoutInflater.from(mContext).inflate(R.layout.inspe_list_item, parent,false);
            return new ViewHolder(item);
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position) {
            String index = datas.get(position);
            if (index.contains("|"))
            {
                String[] infos = index.split("\\|");
                holder.mInfo.setText(infos[1]);
                holder.mTitle.setText(infos[0]);
                holder.mInfo.setTextColor(Color.BLACK);
            }
        }
        @Override
        public int getItemCount() {
            return datas.size();
        }

        public static class ViewHolder extends RecyclerView.ViewHolder {
            public TextView mTitle, mInfo;
            public ViewHolder(View view)
            {
                super(view);
                mTitle = (TextView) view.findViewById(R.id.Title);
                mInfo = (TextView) view.findViewById(R.id.Info);
            }
        }
    }
    private ArrayList<String> init(InspectionForm.InspectionFormListBean mFormListBean){
        ArrayList<String> mInfo = new ArrayList<>();
        mInfo.add(String.format("%s|%s","报检单编号",mFormListBean.number.equals("")?"未知":mFormListBean.number));
        mInfo.add(String.format("%s|%s","建筑物名称",mFormListBean.siteName.equals("")?"未知":mFormListBean.structName));
        switch (mFormListBean.applyMethod)
        {
            case "1":
                mInfo.add(String.format("%s|%s","报检检测方法","低应变"));
                break;
            case "2":
                mInfo.add(String.format("%s|%s","报检检测方法","高应变"));
                break;
            case "3":
                mInfo.add(String.format("%s|%s","报检检测方法","声测"));
                break;
            case "4":
                mInfo.add(String.format("%s|%s","报检检测方法","静载"));
                break;
            default:
                mInfo.add(String.format("%s|%s","报检检测方法","未知"));
                break;
        }
        mInfo.add(String.format("%s|%s","申请人电话",mFormListBean.applicantTel.equals("")?"未知":mFormListBean.applicantTel));
        mInfo.add(String.format("%s|%s","报检时间",mFormListBean.applyTime.equals("")?"未知":mFormListBean.applyTime));
        mInfo.add(String.format("%s|%s","混凝土强度等级",mFormListBean.concreteStrength.equals("")?"未知":mFormListBean.concreteStrength));
        mInfo.add(String.format("%s|%s","设计桩长",mFormListBean.desPileLength.equals("")?"未知":mFormListBean.desPileLength));
        mInfo.add(String.format("%s|%s","成孔方式",mFormListBean.holeMethod.equals("")?"未知":mFormListBean.holeMethod));
        mInfo.add(String.format("%s|%s","设计桩径",mFormListBean.pileDiameter.equals("")?"未知":mFormListBean.pileDiameter));

        mInfo.add(String.format("%s|%s","起始里程",mFormListBean.startMile.equals("")?"未知":mFormListBean.startMile));
        mInfo.add(String.format("%s|%s","结束里程",mFormListBean.endMile.equals("")?"未知":mFormListBean.endMile));
        mInfo.add(String.format("%s|%s","标段名称",mFormListBean.sectName.equals("")?"未知":mFormListBean.sectName));
        mInfo.add(String.format("%s|%s","描述",mFormListBean.describeContents()+" "));
        mInfo.add(String.format("%s|%s","受力类型",mFormListBean.stressType.equals("")?"未知":mFormListBean.stressType));
        return mInfo;
    }
}
